Skip to content

chore(agents): let a rebased branch push without verifying again - #137

Merged
scottlovegrove merged 2 commits into
scottl/agent-guard-pifrom
scottl/agent-push-rebase-exemption
Nov 27, 2026
Merged

scottlovegrove merged 2 commits into
scottl/agent-guard-pifrom
scottl/agent-push-rebase-exemption

Conversation

@scottlovegrove

@scottlovegrove scottlovegrove commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a rebase exemption to the push check from #135, ported from todoist/todoist-cli#676: if a branch's commits are the same changes that passed verify and only main moved under them, the push goes through without running verify again. Without it, every rebase of a verified branch, and of every branch in a stack, needs another verify before it can push.

"The same changes" is a patch id: git patch-id --verbatim over the branch's diff from where it left main, with the diff's context, algorithm and prefixes set by the tooling so git config can't change what it compares. Line numbers may shift, but the changed lines, the lines around them and their whitespace must match, and the new base must contain the one the patch passed on. Patches are recorded in .tmp/agents/verified-patches.json (last 50) when verify passes on a clean tree and when the push check lets a verified commit through. A verify run drops the branch's changes from the record before it checks, whether they're committed, staged or uncommitted (as after git reset HEAD~1), so one that fails, say after a rebase onto a breaking main, leaves them needing verify. A record it can't rewrite is deleted, and verify fails if it can't be deleted either. The check adds a note whenever it lets a push through this way.

The limit is in docs/agents.md: a change elsewhere in main that the branch depends on, such as a renamed function it calls, isn't seen until CI runs on the pushed branch. The code started as todoist-cli's as merged, with every fix from its review. Doistbot's review here found two gaps todoist-cli has too, fixed in e3bf0ea: a failing verify forgot only HEAD's changes, so the same changes staged or uncommitted again kept their pass, and a record it couldn't rewrite was left in place.

Tried with Claude Code (claude -p) in a throwaway clone pushing to a local bare repository: after verify, the push went through; after main moved by hand and the branch was rebased onto it (new commits and a different tree), the force-push went through without verify, with the note "HEAD holds changes that already passed verify, so it isn't verified again"; an unverified change committed on top was then blocked, and the bare repository's ref stayed at the rebased commit.

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds a rebase exemption to the agent push check: branches whose changes already passed verify (matched by git patch-id) can push after a rebase without re-running it, with patch records kept in .tmp/agents/verified-patches.json and an ancestry check ensuring the new base contains the original one.

Few things worth tightening:

  • Invalidation on a failed verify only drops the HEAD patch; if the verified changes are staged/unstaged (e.g. after git reset --soft), the working-tree patch can still satisfy hasPassedPatch after recommitting — invalidate it too and add a regression test.
  • If verified-patches.json is readable but not writable, invalidation failures are swallowed, so a stale entry can survive a failing verify; propagate the error or fall back to deleting the record and failing explicitly.
  • The regression test's deny path doesn't actually exercise the patch-forgetting logic (a missing tree record already denies the push); assert the record contents after the failed run, or keep a verified record for another branch, so the test would fail if forgetPassedPatch were removed.

I also included a few optional follow-up notes in the details below.

Optional follow-up notes (4)
  • P3 .agents/scripts/lib/verify.ts:68: This re-implements resolveCommit from ./git.ts (rev-parse --verify --quiet <ref>^{commit}, returning undefined when it fails), which push-check.ts already uses for exactly this. const commit = resolveCommit(root, 'HEAD') replaces both lines and drops the now-unused git import from this file.
  • P3 .agents/scripts/lib/patches.ts:77: forgetPassedPatch computes the branch patch id (a full git diff of the branch plus git patch-id) before reading the record, so every npm run verify run pays for that diff even when .tmp/agents/verified-patches.json is missing or empty. hasPassedPatch already does the cheap check first (read, return if empty). Move the readPassedPatches call above branchPatchId and return when there's nothing recorded, so the diff only runs when there's a record to remove.
  • P3 .agents/scripts/lib/patches.ts:59: recordPassedPatch runs on every allowed push of a verified commit (push-check.ts calls it in the fingerprint === checkout.verified path), and it always spawns git diff + git patch-id, reads the record, and rewrites it with a new at timestamp — even when the record already holds this patchId on this base. An agent pushing the same branch repeatedly (e.g. while iterating on a stack) pays that on each push for no effect. Since recordPassedPatch already receives the commit, store the commit sha in the record and return early when an entry with the same base and commit exists; that skips both spawns and the write on repeat pushes. Update the toEqual in verify.test.ts that pins the record shape.
  • P3 .agents/scripts/lib/push-check.test.ts:255: describe.skipIf(!GIT_HAS_VERBATIM_PATCH_ID) silently drops these tests on git older than 2.39 without saying why — patches.test.ts:44 carries that comment, this file and verify.test.ts:61/:75 don't. Test rules §5 allows a conditional skip only with a comment explaining it, so add the one-line reason (no git patch-id --verbatim before 2.39, so there is no exemption to test).

Share Feedback • Review Logs • Trace

Comment thread .agents/scripts/lib/verify.ts Resolved
Comment thread .agents/scripts/lib/patches.ts Resolved
Comment thread .agents/scripts/lib/verify.test.ts Resolved
@scottlovegrove
scottlovegrove force-pushed the scottl/agent-push-rebase-exemption branch from d05154f to 07caba0 Compare November 27, 2026 14:04
@scottlovegrove
scottlovegrove force-pushed the scottl/agent-push-rebase-exemption branch from 07caba0 to 5ebad83 Compare November 27, 2026 14:09
@scottlovegrove scottlovegrove added the 🚢 Ship PR requires passing checks before merge, but no independent human review. label Nov 27, 2026
Adds a rebase exemption to the push check, ported from
todoist/todoist-cli#676: if a branch's commits are the same changes
that passed verify and only main moved under them, the push goes
through without running verify again. Without it, every rebase of a
verified branch, and of every branch in a stack, needs another verify
before it can push.

"The same changes" is a patch id: git patch-id --verbatim over the
branch's diff from where it left main, with the diff's context,
algorithm and prefixes set explicitly so git config can't change what
it compares, and the new base must contain the one the patch passed on.
Patches are recorded in .tmp/agents/verified-patches.json (last 50)
when verify passes on a clean tree and when the push check lets a
verified commit through. A verify run drops the branch's changes from
the record before it checks, so one that fails leaves them needing
verify. The check adds a note whenever it lets a push through this way.
A verify run dropped only HEAD's changes from the record of changes
that passed. After `git reset --soft HEAD~1` or `git reset HEAD~1`, the
same changes sat staged or uncommitted, so a failing run forgot nothing
and recommitting them let the push through on the earlier pass. It now
drops HEAD's changes, the staged ones and the whole working tree's,
untracked files included (read through a copy of the index, so the
real one is left alone).

A record it can't rewrite is deleted instead of left in place, and if
it can't be deleted either, verify fails. It reads the record before
computing any patch, so a run with nothing recorded pays for no diff.
The verify test for a failed run now checks the record itself, since a
denied push alone doesn't show the forgetting happened, and each
conditional skip says why.
@scottlovegrove
scottlovegrove force-pushed the scottl/agent-push-rebase-exemption branch from e3bf0ea to 17c3371 Compare November 27, 2026 14:30
@scottlovegrove
scottlovegrove merged commit f3e2afe into main Nov 27, 2026
11 checks passed
@scottlovegrove
scottlovegrove deleted the scottl/agent-push-rebase-exemption branch November 27, 2026 14:35
scottlovegrove added a commit to todoist/todoist-mcp that referenced this pull request Nov 27, 2026
# Pull Request

## Short description

Part 3 of 3, on top of #785. Adds the rebase exemption from
todoist/todoist-cli#676: if a branch's commits are the same changes that
passed verify and only `main` moved under them, the push goes through
without running verify again, with a note saying so. "The same changes"
is `git patch-id --verbatim` over the branch's diff from where it left
`main`, and the new base must contain the one the patch passed on.
Patches are recorded in `.tmp/agents/verified-patches.json` (last 50)
when verify passes on a clean tree and when the check lets a verified
commit through. docs/agents.md states the limit: a change elsewhere in
`main` that the branch depends on isn't seen until CI runs.

Fixes from the other ports, each with a test that fails without it:

- Before it checks, verify forgets the branch's changes as HEAD holds
them, as staged, and as the whole working tree with untracked files
(read through a copy of the index), so a failing run after `git reset
--soft HEAD~1` or `git reset HEAD~1` can't leave them counted as passed
(comms-cli, todoist/comms-cli#137).
- A run the preflight stops (old Node, `node_modules` out of step with
the lockfile, as after a rebase onto new dependencies) forgets them too
(outline-cli todoist/outline-cli#195, zendesk-cli
todoist/zendesk-cli#284).
- A record that can't be rewritten is deleted, and verify fails if it
can't be deleted either, instead of the error being swallowed
(comms-cli, outline-cli).
- The tooling's git calls drop `GIT_DIFF_OPTS`, which would otherwise
shrink the diff's context under `--unified=3` (zendesk-cli), and the
diff sets `--indent-heuristic` so `diff.indentHeuristic` can't change
the id either (outline-cli).
- A test pins that a commit and push in one command is checked against
the working tree, not an earlier passed patch (zendesk-cli).

Tried with Claude Code (`claude -p`, Haiku) in a throwaway clone: after
verify the push went through; after I moved `main` by hand and rebased
the branch (a new commit and a different tree), the force-push went
through without verify, with the note "HEAD holds changes that already
passed verify" in the transcript; an unverified commit on top was then
denied, and the bare repo stayed at the rebased commit.

## PR Checklist

- [x] Added tests for bugs / new features
- [x] Updated docs (README, etc.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚢 Ship PR requires passing checks before merge, but no independent human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants